package com.calm.clibrary.rvadapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * RecyclerView通用多条目适配器
 * Create by Calm
 * on 2019/4/10
 */
public abstract class CommMultiItemRvAdapter<T> extends CommRvAdapter<T>{
    protected MultiItemTypeSupport<T> multiItemTypeSupport;
    public CommMultiItemRvAdapter(Context context, List<T> list,MultiItemTypeSupport<T> multiItemTypeSupport){
        super(context,list,-1);
        this.multiItemTypeSupport = multiItemTypeSupport;
    }

    @Override
    public int getItemViewType(int position) {
        return multiItemTypeSupport.getItemViewType(position,dataList.get(position));
    }

    @NonNull
    @Override
    public CommRvHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        int layoutId = multiItemTypeSupport.getLayoutId(i);
        View itemView = layoutInflater.inflate(layoutId,viewGroup,false);
        return new CommRvHolder(itemView);
    }
}
